﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project_2._2.Models;
using Project_2._2.ViewModels;
using System.IO;
using Project_2._2.Extra;
using System.Web.Security;
using PagedList;
using PagedList.Mvc;

namespace Project_2._2.Controllers
{
    public class BookCarsController : Controller
    {
        //
        // GET: /BookCars/

        private QuanLyThueXeEntities db = new QuanLyThueXeEntities();
        private Common cm = new Common();
        public ActionResult Default(int? page, string rd, string Record)
        {
            if (!Request.IsAuthenticated)
            {
                return RedirectToAction("Login", "Admin");
            }
            else
            {
                if (cm.CheckUserType(User.Identity.Name))
                {
                    if (rd != null)
                    {
                        int record = int.Parse(rd);
                        var dx = (from p in db.DatXes select p).ToList().ToPagedList(page ?? 1, record);
                        ViewBag.record = rd;
                        return View(dx);
                    }
                    else
                    {
                        var dx = (from p in db.DatXes select p).ToList().ToPagedList(page ?? 1, 1);
                        return View(dx);
                    }
                }
                else
                    return RedirectToAction("Login", "Admin");
            } 

        }

    }
}
